<template>
    <div class="mainDiv" style="color:#000">
        <el-row>
            <el-steps :active="active" center finish-status="success" style="margin: 15px 15px 0px !important" align-center>
                <el-step title="开单"></el-step>
                <el-step title="结账分配业绩"></el-step>
                <el-step title="分配提成"></el-step>
            </el-steps>
        </el-row>
        <el-row :gutter="20" v-if="active == 0" class="mainDiv" style="margin: 0px">
            <el-form ref="form" label-width="80px" class="mainDiv">
                <el-form-item label="开单客户">
                    <div style="height:62px">
                        <div style="float:left;">
                            <el-select v-model="ginfo.name" filterable remote placeholder="请输入关键词" :remote-method="searchguest" :loading="loading" @change="selectguest" default-first-option style="float: left;margin-right: 10px;" :disabled="issanke">
                                <el-option v-for="item in guestlist" :key="item.id" :label="item.name" :value="item.id" style="height: 68px">
                                    <div style="display: flex; flex-direction: column">
                                        <div>
                                            <span style="font-weight: 900;">{{item.name}}</span>
                                            <span style="float: right;font-size: 11px;color: #dc35af;">{{item.shopname}}</span>
                                        </div>
                                        <span style="font-size: 12px;margin-left: 10px;">{{item.phone}}</span>
                                    </div>
                                </el-option>
                            </el-select>
                            <div>
                                <el-switch @change="changesanke" v-model="issanke" style="margin: 0px 10px 0px 0px;" on-text="散" off-text="散" :width="45"></el-switch>
                                <el-radio v-model="ginfoid" :label="1" v-show="issanke">女</el-radio>
                                <el-radio v-model="ginfoid" :label="2" v-show="issanke">男</el-radio>
                            </div>
                        </div>
                        <div style="width:450px; float: left" v-show="ginfo.id && !issanke">
                            <el-card :body-style="{ padding: '0px' }">
                                <el-row>
                                    <div style="float: left;height: 60px;margin-right: 10px">
                                        <img :src="ginfo.headurl" style="border-radius: 50%; width: 50px; height:50px;padding: 5px">
                                    </div>
                                    <div style="float: left;height: 60px;">
                                        <p style="margin: 0px; height: 30px">
                                            <span @click="openGuestPage(ginfo.id)" style="cursor:pointer;color:#f50">{{ginfo.name}}</span>
                                            <span style="margin-left: 10px;font-size: 13px;color: #999;"><i class="iconfont el-icon-h-dianhua1"></i> {{ginfo.phone}}</span>
                                            <span style="margin-left: 10px;font-size: 13px;color: #999;"><i class="iconfont el-icon-h-yue01"></i> {{ginfo.balance}}</span>
                                            <span style="margin-left: 10px;font-size: 13px;color: #999;"><i class="iconfont el-icon-h-zengsong"></i> {{ginfo.giftbalance}}</span>
                                        </p>
                                        <p style="margin: 0px; height: 30px">
                                            <span style="font-size: 13px;color: #999;"><i class="iconfont el-icon-h-level"></i> {{ginfo.vipcard}}</span> 产品折扣：
                                            <span style="font-size: 13px;color: #999;">{{ginfo.goodsdiscount}}</span> 项目折扣：
                                            <span style="font-size: 13px;color: #999;">{{ginfo.subjectdiscount}}</span>
                                        </p>
                                    </div>
                                </el-row>
                            </el-card>
                        </div>
                        <div style="width:330px; float: left;margin-left: 10px" v-show="ginfo.id && !issanke">
                            <el-input type="textarea" :rows="3" v-model="ginfo.remarks">
                            </el-input>
                        </div>
                    </div>
                </el-form-item>
                <el-form-item label="消费内容" class="itemClass">
                    <div>
                        <el-button type="primary" icon="plus" size="small" @click="addRow(orderListRef)">加一行</el-button>
                    </div>
                    <el-table style="width: 100%" :data="orderlist" height="100%" show-summary :summary-method="sumorderlist">
                        <el-table-column prop="rowtype" label="类别" width="60">
                            <template scope="scope">
                                <el-input :value="returnValue(scope, orderListRowType)" size="small" :ref="makeIndex(scope.$index, 1, orderListRef)" @focus="setIndex(scope.$index, 1, orderListRef)" @blur="checkValue($event, scope, orderListRowType)" @keyup.enter.native="selectValue($event, scope, orderListRowType, orderListRef)">
                                </el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="typename" label="品项名称" width="130" :show-overflow-tooltip="true">
                            <template scope="scope">
                                <el-input :ref="makeIndex(scope.$index, 2, orderListRef)" @focus="setIndex(scope.$index, 2, orderListRef)" :value="scope.row.typename" size="small" @blur="blurcheck($event, scope.row.typename)" @keyup.enter.native="searchOpenOrderGoods($event, scope)">
                                    <i slot="suffix" class="el-icon-search" style="line-height: 32px;width: 25px;cursor: pointer;" @click="firstPopupType(scope)"></i>
                                </el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="type" label="消费类型" width="58">
                            <template scope="scope">
                                <el-tag size="mini" type="success" v-if="scope.row.type == 1">产品</el-tag>
                                <el-tag size="mini" type="primary" v-else>项目</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column prop="cardname" label="所属卡"></el-table-column>
                        <el-table-column prop="price" label="原价"></el-table-column>
                        <el-table-column prop="num" label="数量" width="50">
                            <template scope="scope">
                                <span v-if="scope.row.consumetype == 2 && scope.row.cardtype == 1">{{scope.row.num}}</span>
                                <el-input :ref="makeIndex(scope.$index, 3, orderListRef)" @focus="setIndex(scope.$index, 3, orderListRef)" v-model="scope.row.num" size="small" v-else @keyup.native="getTotal(scope.row)" @keyup.enter.native="nextInput(orderListRef)">
                                </el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="nownum" label="可用">
                            <template scope="scope">
                                <span v-if="scope.row.cardtype == 2 || scope.row.consumetype == 3">{{scope.row.nownum}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="discount" label="折扣">
                            <template scope="scope">
                                <span v-if="scope.row.consumetype != 1">{{scope.row.discount}}</span>
                                <el-input v-else :ref="makeIndex(scope.$index, 4, orderListRef)" @focus="setIndex(scope.$index, 4, orderListRef)" style="width:80px" v-model="scope.row.discount" size="small" @keyup.native="getTotal(scope.row)" @keyup.enter.native="nextInput(orderListRef)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="amount" label="小计" width="80">
                            <template scope="scope">
                                <el-input v-if="scope.row.consumetype == 1 || scope.row.cardtype == 1" :ref="makeIndex(scope.$index, 5, orderListRef)" @focus="setIndex(scope.$index, 5, orderListRef)" v-model="scope.row.amount" size="small" @change="getdiscount(scope.row)" @keyup.enter.native="nextInput(orderListRef)"></el-input>
                                <span v-else>{{scope.row.amount}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="usemoney" label="现金">
                            <template scope="scope">
                                <el-input :ref="makeIndex(scope.$index, 6, orderListRef)" v-if="scope.row.consumetype == 1 || scope.row.cardtype == 1" @focus="setIndex(scope.$index, 6, orderListRef)" @keyup.enter.native="nextInput(orderListRef)" class="money" placeholder="元" v-model="scope.row.usemoney" size="small"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="usebalance" label="余额">
                            <template scope="scope">
                                <el-input :ref="makeIndex(scope.$index, 7, orderListRef)" v-if="scope.row.consumetype == 1 || scope.row.cardtype == 1" @focus="setIndex(scope.$index, 7, orderListRef)" @keyup.enter.native="nextInput(orderListRef)" class="money" placeholder="元" v-model="scope.row.usebalance" size="small" :disabled="issanke"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="usegiftbalance" label="赠送余额">
                            <template scope="scope">
                                <el-input :ref="makeIndex(scope.$index, 8, orderListRef)" v-if="scope.row.consumetype == 1 || scope.row.cardtype == 1" @focus="setIndex(scope.$index, 8, orderListRef)" @keyup.enter.native="nextInput(orderListRef)" class="money" placeholder="元" v-model="scope.row.usegiftbalance" size="small" :disabled="issanke"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="usecard" label="卡付">
                        </el-table-column>
                        <el-table-column prop="isgift" label="赠">
                            <template scope="scope">
                                <el-input style="width:50px" v-if="scope.row.consumetype == 1" :ref="makeIndex(scope.$index, 9, orderListRef)" @focus="setIndex(scope.$index, 9, orderListRef)" :value="returnValue(scope, trueOrFalse)" @blur="checkValue($event, scope, trueOrFalse)" size="small" @keyup.enter.native="selectValue($event, scope, trueOrFalse, orderListRef)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="istemp" label="存">
                            <template scope="scope">
                                <el-input style="width:50px" v-if="scope.row.type == 1 && scope.row.consumetype == 1 && !issanke" :ref="makeIndex(scope.$index, 10, orderListRef)" @focus="setIndex(scope.$index, 10, orderListRef)" :value="returnValue(scope, trueOrFalse)" @blur="checkValue($event, scope, trueOrFalse)" size="small" @keyup.enter.native="selectValue($event, scope, trueOrFalse, orderListRef)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="" label="操作" width="60">
                            <template scope="scope">
                                <el-button type="danger" size="mini" @click="deleterow(scope.$index, orderlist)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-form-item>
                <el-form-item label="消费总计">
                    <el-tag size="small" type="success">现金消费</el-tag> +
                    <el-tag size="small">余额消费</el-tag> +
                    <el-tag size="small" type="info">赠送余额</el-tag> +
                    <el-tag size="small" type="danger">卡耗消费</el-tag> = {{fenpeijine.usemoney.toFixed(2)}} + {{fenpeijine.usebalance.toFixed(2)}} + {{fenpeijine.usegiftbalance.toFixed(2)}} + {{fenpeijine.usecard.toFixed(2)}} = {{fenpeijine.zongji.toFixed(2)}}
                </el-form-item>
                <el-form-item label="订单备注">
                    <el-input type="textarea" v-model="order.remarks" placeholder="请输入当前订单描述信息"></el-input>
                </el-form-item>
                <div style="padding: 10px;box-sizing: border-box;">
                    <!-- <el-button style="float:right;margin-left:10px" type="primary" icon="upload2" @click="step(1)">去结账</el-button> -->
                    <el-button style="float:right" type="primary" icon="upload2" @click="submitorder(1)" v-qx="quanxian.add">保存并结账</el-button>
                    <!-- <el-button style="float:right" type="primary" icon="upload2" @click="submitorder(0)">保存单据</el-button> -->
                    <el-button style="margin: 0px" type="danger" icon="close" @click="closewin">取消关闭</el-button>
                </div>
            </el-form>
        </el-row>
        <el-row :gutter="20" v-else style="margin: 0px">
            <el-col :span="24">
                <el-tabs v-model="activeName">
                    <el-tab-pane label="开单结账" name="first" v-if="active == 1">
                        <el-col :span="12">
                            <el-form ref="form" label-width="70px">
                                <el-form-item label="支付信息">
                                    <p style="margin:0px">
                                        订单总计：现金消费 + 余额消费 + 赠送余额 + 卡耗消费 = {{(fenpeijine.usemoney).toFixed(2)}} + {{(fenpeijine.usebalance).toFixed(2)}} + {{(fenpeijine.usegiftbalance).toFixed(2)}} + {{(fenpeijine.usecard).toFixed(2)}} = {{(fenpeijine.zongji).toFixed(2)}}元
                                    </p>
                                    <p style="margin:0px">
                                        已支付：卡耗 + 余额 + 赠送余额 = {{(fenpeijine.usecard).toFixed(2)}} + {{(fenpeijine.usebalance).toFixed(2)}} + {{(fenpeijine.usegiftbalance).toFixed(2)}} = {{(fenpeijine.usecard + fenpeijine.usebalance + fenpeijine.usegiftbalance).toFixed(2)}} 元
                                    </p>
                                    <p style="margin:0px">
                                        应支付：现金支付 = {{fenpeijine.usemoney}} 元
                                    </p>
                                </el-form-item>
                                <el-form-item label="跟单人员">
                                    <template>
                                        <el-select v-model="order.gendanid" filterable remote reserve-keyword :remote-method="selectUser" :loading="loading">
                                            <el-option :value="0" label="请选择"></el-option>
                                            <el-option v-for="item in userlist" :key="item.id" :label="item.name" :value="item.id">
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-form-item>
                                <el-form-item label="付款信息">
                                    <template v-if="order.status == 0">
                                        <el-button icon="plus" type="primary" size="small" @click="addRow(payListRef)" class="mb">加一行</el-button>
                                    </template>
                                    <el-table :data="paylist" height="300">
                                        <el-table-column prop="accountname" label="收款账户" :show-overflow-tooltip="showOwer">
                                            <template scope="scope">
                                                <el-input :ref="makeIndex(scope.$index, 1, payListRef)" @focus="setIndex(scope.$index, 1, payListRef)" @blur="blurcheck($event, scope.row.accountname)" @keyup.enter.native="searchAccount($event, scope)" :value="scope.row.accountname" size="small" v-if="order.status == 0">
                                                    <i slot="suffix" class="el-icon-search" style="line-height: 32px;width: 25px;cursor: pointer;" @click="firstPopupAccount(scope)"></i>
                                                </el-input>
                                                <span v-else>{{scope.row.accountname}}</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="type" label="收款方式" width="98">
                                            <template scope="scope">
                                                <el-tag size="mini" type="success" v-if="scope.row.type == 1">现金支付</el-tag>
                                                <el-tag size="mini" type="primary" v-else-if="scope.row.type == 2">可用余额</el-tag>
                                                <el-tag size="mini" type="primary" v-else>赠送余额</el-tag>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="paymoney" label="收款金额">
                                            <template scope="scope">
                                                <el-input placeholder="元" :ref="makeIndex(scope.$index, 2, payListRef)" @focus="setIndex(scope.$index, 2, payListRef)" v-model="scope.row.paymoney" @keyup.enter.native="nextInput(payListRef)" size="small" v-if="order.status == 0"></el-input>
                                                <span v-else>{{scope.row.paymoney}}</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="" label="操作" width="80" v-if="order.status == 0">
                                            <template scope="scope">
                                                <el-button type="danger" size="mini" @click="deleterow(scope.$index, paylist)" v-show="scope.row.type == 1">删除</el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                    <el-tag type="danger" class="fr" v-if="yingshoujine > 0">应收现金：{{yingshoujine+'元'}}</el-tag>
                                </el-form-item>
                            </el-form>
                        </el-col>
                        <el-col :span="12">
                            <!-- 现金业绩 -->
                            <el-form ref="form" label-width="80px">
                                <el-form-item label="现金业绩" v-show="fenpeijine.usemoney > 0 || fenpeijine.usegiftbalance + fenpeijine.usebalance + fenpeijine.usecard > 0">
                                    <el-button icon="plus" type="primary" size="small" @click="addRow(yejiListRef)">加员工</el-button>
                                    <el-button style="float:right;" type="primary" size="small" icon="upload2" v-if="order.status != 0" @click="chongxinfenpei">重新分配</el-button>
                                    <el-table :data="yejilist" max-height="250">
                                        <el-table-column prop="name" label="姓名">
                                            <template scope="scope">
                                                <el-input :ref="makeIndex(scope.$index, 1, yejiListRef)" @focus="setIndex(scope.$index, 1, yejiListRef)" @blur="blurcheck($event, scope.row.name)" @keyup.enter.native="searchUser($event, scope)" :value="scope.row.name" size="small">
                                                    <i slot="suffix" class="el-icon-search" style="line-height: 32px;width: 25px;cursor: pointer;" @click="firstPopupUser(scope)"></i>
                                                </el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="fuwutype" label="属性" width="98">
                                            <template scope="scope">
                                                <el-input :ref="makeIndex(scope.$index, 2, yejiListRef)" @focus="setIndex(scope.$index, 2, yejiListRef)" :value="returnValue(scope, fuwuType)" @blur="checkValue($event, scope, fuwuType)" size="small" @keyup.enter.native="selectValue($event, scope, fuwuType, yejiListRef)"></el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="xianjinyeji" label="现金业绩">
                                            <template scope="scope">
                                                <el-input :ref="makeIndex(scope.$index, 3, yejiListRef)" @focus="setIndex(scope.$index, 3, yejiListRef)" v-model="scope.row.xianjinyeji" size="small" @keyup.enter.native="nextInput(yejiListRef)">
                                                </el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="kahaoyeji" label="卡耗业绩">
                                            <template scope="scope">
                                                <el-input :ref="makeIndex(scope.$index, 4, yejiListRef)" @focus="setIndex(scope.$index, 4, yejiListRef)" v-model="scope.row.kahaoyeji" size="small" @keyup.enter.native="nextInput(yejiListRef)">
                                                </el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="" label="操作" width="80">
                                            <template scope="scope">
                                                <el-button type="danger" size="mini" @click="deleterow(scope.$index, yejilist)">删除</el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                    <el-row>
                                        <el-col :span="24" style="text-align:right">
                                            <span style="background-color:#f3b5b5;border-radius:3px;color:#fff;padding:3px" v-show="yingfenyeji.yingfenxianjin != 0">现金差：{{yingfenyeji.yingfenxianjin}}元</span>
                                            <span style="background-color:#f3b5b5;border-radius:3px;color:#fff;padding:3px" v-show="yingfenyeji.yingfenkahao != 0">卡耗差：{{yingfenyeji.yingfenkahao}}元</span>
                                        </el-col>
                                    </el-row>
                                </el-form-item>
                            </el-form>
                        </el-col>
                        <div style="position: fixed;bottom: 20px;width: 100%;padding: 0px 20px;box-sizing: border-box;left: 0px;">
                            <el-button type="danger" class="fr" style="float: left;" @click="step(0)">编辑订单</el-button>
                            <el-button style="float:right;" type="primary" @click="step(2)">下一步</el-button>
                            <el-button icon="check" type="success" style="float:right" @click="paysubmit" v-if="order.status == 0" v-qx="quanxian.jiezhang">确定结账</el-button>
                            <el-button icon="check" type="warning" style="float:right" @click="fanjiezhang" v-else v-qx="quanxian.fanjiezhang">反结账</el-button>
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="分配提成" name="first" v-if="active == 2">
                        <el-row :gutter="20">
                            <el-col :span="24">
                                <el-table :data="tichenglist" style="width: 100%;" height="250" show-summary :summary-method="gettichengsum">
                                    <el-table-column prop="type" label="品项类型" width="98">
                                        <template scope="scope">
                                            <el-tag size="mini" type="success" v-if="scope.row.type == 1">产品</el-tag>
                                            <el-tag size="mini" type="warning" v-if="scope.row.type == 2">项目</el-tag>
                                            <el-tag size="mini" type="primary" v-if="scope.row.type == 3">卡</el-tag>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="typename" label="品项名称" width="130" :show-overflow-tooltip="showOwer"></el-table-column>
                                    <el-table-column prop="consumetype" label="消费类型">
                                        <template scope="scope">
                                            <el-tag size="mini" type="success" v-if="scope.row.consumetype == 1">普通消费</el-tag>
                                            <el-tag size="mini" type="danger" v-else-if="scope.row.consumetype == 2">卡项消费</el-tag>
                                            <el-tag size="mini" type="gray" v-else>暂存消费</el-tag>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="price" label="原价"></el-table-column>
                                    <el-table-column prop="num" label="数量">
                                    </el-table-column>
                                    <el-table-column prop="discount" label="折扣（0-1）" width="130">
                                    </el-table-column>
                                    <el-table-column prop="amount" label="小计">
                                    </el-table-column>
                                    <el-table-column prop="xianjinticheng" label="现金提成">
                                    </el-table-column>
                                    <el-table-column prop="kahaoticheng" label="卡耗提成">
                                    </el-table-column>
                                    <el-table-column prop="shougongticheng" label="手工提成">
                                    </el-table-column>
                                </el-table>
                                <el-button type="primary" icon="plus" size="small" @click="adduser" style="margin:5px 0px">员工</el-button>
                                <el-table :data="fenpeilist" style="width: 100%" show-summary :summary-method="getSummaries" height="260">
                                    <el-table-column prop="name" label="姓名" width="180">
                                    </el-table-column>
                                    <el-table-column prop="xianjinyeji" label="现金业绩">
                                    </el-table-column>
                                    <el-table-column prop="kahaoyeji" label="卡耗业绩">
                                    </el-table-column>
                                    <el-table-column prop="xianjinticheng" label="现金提成">
                                        <template scope="scope">
                                            <el-input size="small" style="width:100px" v-model="scope.row.xianjinticheng" v-show="scope.row.addtype == 0"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="kahaoticheng" label="卡耗提成">
                                        <template scope="scope">
                                            <el-input size="small" style="width:100px" v-model="scope.row.kahaoticheng" v-show="scope.row.addtype == 0"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="shougongticheng" label="手工提成">
                                        <template scope="scope">
                                            <el-input size="small" style="width:100px" v-model="scope.row.shougongticheng" v-show="scope.row.addtype == 0"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="qitaticheng" label="其他提成">
                                        <template scope="scope">
                                            <el-input size="small" style="width:100px;margin:5px" v-model="scope.row.qitaticheng" v-show="scope.row.addtype == 1"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="address" label="操作">
                                        <template scope="scope">
                                            <el-button type="danger" size="mini" @click="deleterow(scope.$index, fenpeilist)" :disabled="scope.row.addtype == 0">删除</el-button>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </el-col>
                        </el-row>
                        <div style="position: fixed;bottom: 20px;width: 100%;padding: 0px 20px;box-sizing: border-box;left: 0px;">
                            <el-button type="danger" class="fr" style="float: left;" @click="step(1)">上一步</el-button>
                            <el-button style="float: left;" @click="dayin" v-qx="quanxian.dayin">打印</el-button>
                            <el-button type="primary" style="float: right" icon="upload2" @click="fenpeiticheng(0)" v-show="order.status == 1" v-qx="quanxian.fenpei">保存分配</el-button>
                            <el-button type="primary" style="float: right" @click="step(3)" v-show="order.status == 2">下一步</el-button>
                            <el-button type="primary" style="float: right" @click="fenpeiticheng(1)" v-show="order.status == 2" v-qx="quanxian.chongxinfenpei">重新分配</el-button>
                            <el-button type="danger" style="float: right" @click="quxiaofenpei" v-show="order.status == 2" v-qx="quanxian.fanfenpei">取消分配</el-button>
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="订单完成" name="first" v-if="active == 3">
                        <el-table :data="paylist" height="250">
                            <el-table-column prop="type" label="付款方式">
                                <template scope="scope">
                                    <el-tag size="mini" type="success" v-if="scope.row.type == 1">现金支付</el-tag>
                                    <el-tag size="mini" type="primary" v-else-if="scope.row.type == 2">可用余额</el-tag>
                                    <el-tag size="mini" type="primary" v-else>赠送余额</el-tag>
                                </template>
                            </el-table-column>
                            <el-table-column prop="accountname" label="收款账户" width="130" :show-overflow-tooltip="showOwer">
                            </el-table-column>
                            <el-table-column prop="paymoney" label="收款金额">
                            </el-table-column>
                        </el-table>
                        <el-table :data="fenpeilist" style="width: 100%" show-summary :summary-method="getSummaries" height="260">
                            <el-table-column prop="name" label="姓名" width="180">
                            </el-table-column>
                            <el-table-column prop="xianjinyeji" label="现金业绩">
                            </el-table-column>
                            <el-table-column prop="kahaoyeji" label="卡耗业绩">
                            </el-table-column>
                            <el-table-column prop="xianjinticheng" label="现金提成">
                            </el-table-column>
                            <el-table-column prop="kahaoticheng" label="卡耗提成">
                            </el-table-column>
                            <el-table-column prop="shougongticheng" label="手工提成">
                            </el-table-column>
                            <el-table-column prop="qitaticheng" label="其他提成">
                            </el-table-column>
                        </el-table>
                        <div style="position: fixed;bottom: 20px;width: 100%;padding: 0px 20px;box-sizing: border-box;left: 0px">
                            <el-button type="danger" class="fr" style="float: left;" @click="step(2)">上一步</el-button>
                            <el-button icon="check" type="success" style="float: right;" @click="closewin">完成</el-button>
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="订单详情" name="second">
                        <el-form ref="form" label-width="80px" class="mt">
                            <el-form-item label="开单客户">
                                <div style="height:62px">
                                    <div style="width:400px; float: left" v-show="ginfo.id">
                                        <el-card :body-style="{ padding: '0px' }">
                                            <el-row>
                                                <div style="float: left;height: 60px;margin-right: 10px">
                                                    <img :src="ginfo.headurl" style="border-radius: 50%; width: 50px; height:50px;padding: 5px">
                                                </div>
                                                <div style="float: left;height: 60px;">
                                                    <p style="margin: 0px; height: 30px">
                                                        <span @click="openGuestPage(ginfo.id)" style="cursor:pointer;color:#f50">{{ginfo.name}}</span>
                                                        <span style="margin-left: 10px;font-size: 13px;color: #999;">{{ginfo.phone}}</span>
                                                    </p>
                                                    <p style="margin: 0px; height: 30px">
                                                        vip：<span style="font-size: 13px;color: #999;">{{ginfo.vipcard}}</span> 产品折扣：
                                                        <span style="font-size: 13px;color: #999;">{{ginfo.goodsdiscount}}</span> 项目折扣：
                                                        <span style="font-size: 13px;color: #999;">{{ginfo.subjectdiscount}}</span>
                                                    </p>
                                                </div>
                                            </el-row>
                                        </el-card>
                                    </div>
                                </div>
                            </el-form-item>
                            <el-form-item label="开单列表">
                                <el-row>
                                    <el-table :data="orderlist" :height="380" show-summary :summary-method="sumorderlist">
                                        <el-table-column type="index" label="序号" width="50"></el-table-column>
                                        <el-table-column prop="type" label="品项类型" width="80">
                                            <template scope="scope">
                                                <el-tag size="mini" type="success" v-if="scope.row.type == 1">产品</el-tag>
                                                <el-tag size="mini" type="primary" v-else>项目</el-tag>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="typename" label="品项名称" width="130" :show-overflow-tooltip="true"></el-table-column>
                                        <el-table-column prop="consumetype" label="消费类型">
                                            <template scope="scope">
                                                <el-tag size="mini" type="success" v-if="scope.row.consumetype == 1">普通消费</el-tag>
                                                <el-tag size="mini" type="danger" v-else-if="scope.row.consumetype == 2">卡项消费</el-tag>
                                                <el-tag size="mini" type="gray" v-else>暂存消费</el-tag>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="cardname" label="所属卡"></el-table-column>
                                        <el-table-column prop="price" label="原价"></el-table-column>
                                        <el-table-column prop="num" label="数量" width="50">
                                        </el-table-column>
                                        <el-table-column prop="discount" label="折扣" width="50">
                                        </el-table-column>
                                        <el-table-column prop="amount" label="小计" width="80">
                                        </el-table-column>
                                        <el-table-column prop="usemoney" label="现金">
                                        </el-table-column>
                                        <el-table-column prop="usebalance" label="余额">
                                        </el-table-column>
                                        <el-table-column prop="usegiftbalance" label="赠送余额">
                                        </el-table-column>
                                        <el-table-column prop="usecard" label="卡付">
                                        </el-table-column>
                                        <el-table-column prop="isgift" label="赠">
                                            <template scope="scope">
                                                <el-input style="width:50px" v-if="scope.row.consumetype == 1" :value="returnValue(scope, trueOrFalse)" size="small" disabled></el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="istemp" label="存">
                                            <template scope="scope">
                                                <el-input style="width:50px" v-if="scope.row.type == 1 && scope.row.consumetype == 1 && !issanke" :value="returnValue(scope, trueOrFalse)" size="small" disabled></el-input>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </el-row>
                            </el-form-item>
                            <el-form-item label="开单描述">
                                <el-input type="textarea" v-model="order.remarks" placeholder="请输入开单描述，方便了解该订单。（可忽略）" disabled></el-input>
                            </el-form-item>
                        </el-form>
                    </el-tab-pane>
                </el-tabs>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import C from '#/src/common/common.js'
import S from '#/src/shop/search.js'
import P from '#/src/shop/popup.js'
import D from '#/src/common/datas.js'
import keyUpRef from '#/src/shop/keyupref.js'
import Guest from '#/src/shop/guest.js'
import headImg from '#/static/img/headimg.jpg'
export default {
    name: 'openOrder',
    data() {
        return {
            // 重新规划数据
            // 初始化
            // 重要数据（开单）
            order: {
                id: '',
                status: '',
                remarks: ''
            },
            orderlist: [],
            ginfo: {},
            // 结账
            paylist: [],
            yejilist: [],
            // 分配
            fenpeilist: [],
            tichenglist: [],

            //杂项
            guestlist: [], // 选择客户杂项
            loading: true,
            active: 0,
            showOwer: true,
            activeName: 'first',
            labelPosition: 'top',
            ordermoney: 0,
            issanke: false,
            userlist: [],
            orderListRef: D.openOrder.inputRef,
            orderListRowType: D.openOrder.rowType,
            trueOrFalse: D.trueOrFalse,
            payListRef: D.payListRef,
            yejiListRef: D.yejiListRef,
            fuwuType: D.fuwuType,
            ginfoid: 1,
            quanxian: {
                add: 'order_add',
                jiezhang: 'order_jie',
                fanjiezhang: 'order_fan',
                dayin: 'order_print',
                fenpei: 'order_fen',
                fanfenpei: 'order_fanfen',
                chongxinfenpei: 'order_chongxin'
            }
        }
    },
    methods: C.assign(keyUpRef, {
        returnValue(scope, data) {
            for (var i = data.length - 1; i >= 0; i--) {
                if (scope.row[scope.column.property] == data[i].value) {
                    return data[i].name
                }
            }
            return ''
        },
        blurcheck: function(e, value) {
            e.target.value = value
        },
        checkValue(e, scope, data) {
            e.target.value = this.returnValue(scope, data)
        },
        selectValue(e, scope, data, ref) {
            let v = e.target.value
            let isHave = false
            data.forEach((row) => {
                if (row.name == v || row.value == v) {
                    isHave = true
                    if (scope.row[scope.column.property] != row.value) {
                        scope.row[scope.column.property] = row.value
                        // 如果是赠送赋值为零
                        if ('isgift' == scope.column.property) {
                            this.changeStatus(scope.row)
                        }
                        // 如果是类别清空当前行数据
                        if ('rowtype' == scope.column.property) {
                            let data = C.copy(D.openOrderListRow)
                            data.rowtype = row.value
                            scope.row = Object.assign(scope.row, data)
                        }
                    }
                    e.target.value = row.name
                    this.nextInput(ref)
                }
            })
            if (!isHave) {
                C.error('请输入正确的值！')
                e.target.select()
            }
        },
        async searchOpenOrderGoods(e, scope) {
            // 选择客户
            if (!this.ginfo.id || this.ginfo.id == 0) {
                C.error('请先选择客户！')
                return false
            }
            // 判断是否选择行类型
            if (!scope.row.rowtype) {
                C.error('请先选择行类型！')
                return false
            }
            // 开启防重复点击
            if (!C.openLoading()) return false
            let filter = { guestid: this.ginfo.id, keywords: e.target.value, rowtype: scope.row.rowtype }
            let data = await S.searchOpenOrderGoods(filter)
            data = data.data.length == 1 ?
                data.data[0] :
                await P.openOrderGoodsPopup(filter, data)
            C.closeLoading()

            if (data && data.id) {
                let consumetype = scope.row.rowtype == 1 || scope.row.rowtype == 2 ? 1 : scope.row.rowtype == 3 ? 2 : 3
                let type = scope.row.rowtype == 1 || scope.row.rowtype == 4 ? 1 : 2
                // console.log(data)
                // 不存在插入，存在进行如下判断
                // 有数据同一行跳转，有数据不同行提示不能重复
                // 判断是否重复（如果rowtype=1或=2产品项目，可通过rowtype和typeid判断）
                // 如果rowtype=3 可以通过rowtype和guestcardinfoid判断
                // 如果rowtype=4 可通过rowtype和tempid判断

                let index, rowdata = {
                    type: type,
                    typename: data.name,
                    consumetype: consumetype,
                    price: data.price,
                    brandid: data.brandid,
                    goodsnum: data.nums
                }
                switch (scope.row.rowtype) {
                    case 1:
                    case 2:
                        index = C.inarray({ rowtype: scope.row.rowtype, typeid: data.id }, this.orderlist)
                        rowdata = Object.assign(rowdata, {
                            typeid: data.id,
                            amount: data.price,
                        })
                        break
                    case 3:
                        index = C.inarray({ rowtype: scope.row.rowtype, guestcardinfoid: data.id }, this.orderlist)
                        console.log(data)
                        let amount = data.cardtype == 1 ? data.xhprice : data.disprice.toFixed(2) - data.amount > 0 ? data.amount : data.disprice.toFixed(2)
                        let discount = data.cardtype == 1 ? (amount / data.price).toFixed(2) : data.discount
                        rowdata = Object.assign(rowdata, {
                            typeid: data.subjectid,
                            amount: amount,
                            leftAmount: data.amount,
                            nownum: data.cardtype == 1 ? '' : data.nownum,
                            discount: discount,
                            cardtype: data.cardtype,
                            cardname: data.cardname,
                            guestcardid: data.cardid,
                            guestcardinfoid: data.id,
                            usecard: data.cardtype == 1 ? 0 : data.disprice.toFixed(2) - data.amount > 0 ? data.amount : data.disprice.toFixed(2)
                        })
                        break
                    case 4:
                        index = C.inarray({ rowtype: scope.row.rowtype, tempid: data.id }, this.orderlist)
                        rowdata = Object.assign(rowdata, {
                            typeid: data.goodsid,
                            nownum: data.nownum,
                            discount: 0,
                            amount: 0,
                            brandid: data.brandid,
                            tempid: data.id
                        })
                        break
                }

                if (index == -1) {
                    scope.row = Object.assign(scope.row, rowdata)
                    this.nextInput(this.orderListRef)
                } else if (scope.$index == index) {
                    this.nextInput(this.orderListRef)
                } else {
                    C.error('选择数据重复！')
                    e.target.select()
                    return false
                }
            }
        },
        async searchAccount(e, scope) {
            if (!C.openLoading()) return false
            let data = await S.searchAccount({ keywords: e.target.value })
            data = data.list.length == 1 ?
                data.list[0] :
                await P.accountPopup({ keywords: e.target.value }, data)
            C.closeLoading()

            if (data.id) {
                // 判断是否重复
                let key = C.inarray({ accountid: data.id }, this.paylist)
                if (key == -1) {
                    scope.row.accountid = data.id
                    scope.row.accountname = data.name
                    this.nextInput(this.payListRef)
                } else if (scope.$index == key) {
                    this.nextInput(this.payListRef)
                } else {
                    C.error('选择账户重复！')
                    e.target.select()
                    return false
                }
            }
        },
        async firstPopupAccount(scope) {
            this.setIndex(scope.$index, 1, this.payListRef)
            let data = await P.accountPopup({ keywords: '' })
            if (data && data.id) {
                // 判断是否重复
                let key = C.inarray({ accountid: data.id }, this.paylist)
                if (key == -1) {
                    scope.row.accountid = data.id
                    scope.row.accountname = data.name
                    this.nextInput(this.payListRef)
                } else if (scope.$index == key) {
                    this.nextInput(this.payListRef)
                } else {
                    C.error('选择账户重复！')
                    // e.target.select()
                    return false
                }
            }
        },
        async firstPopupUser(scope) {
            this.setIndex(scope.$index, 1, this.yejiListRef)
            let data = await P.userPopup({ keywords: '', guestid: this.ginfo.id })
            if (data && data.id) {
                // 判断是否重复
                let key = C.inarray({ userid: data.id }, this.yejilist)
                if (key == -1) {
                    scope.row.userid = data.id
                    scope.row.name = data.name
                    scope.row.bumenid = data.bumenid
                    scope.row.xiaozuid = data.xiaozuid
                    this.nextInput(this.yejiListRef)
                } else if (scope.$index == key) {
                    this.nextInput(this.yejiListRef)
                } else {
                    C.error('选择员工重复！')
                    // e.target.select()
                    return false
                }
            }
        },
        selectguest: function(id) {
            this.guestlist.forEach((row) => {
                if (row.id == id) {
                    row.headurl = row.headurl != 0 ? row.headurl : headImg
                    this.ginfo = Object.assign({}, row)
                    this.orderlist = []
                    this.addRow(this.orderListRef)
                }
            })
        },
        searchguest: async function(search) {
            let that = this
            if (search != '') {
                this.loading = true
                let data = { pagesize: 30, currentpage: 1, search: search }
                let list = await Guest.getDepartmentGuestList(data)
                that.loading = false
                that.guestlist = list.data
            }
        },
        async selectUser(str) {
            this.loading = true
            let filter = { pagesize: 30, currentpage: 1, keywords: str, ismanage: 1 }
            let userList = await S.searchUser(filter)
            this.loading = false
            this.userlist = userList.list
        },
        async searchUser(e, scope) {
            if (!C.openLoading()) return false
            let filter = { keywords: e.target.value, guestid: this.ginfo.id }
            let data = await S.searchUser(filter)
            data = data.list.length == 1 ?
                data.list[0] :
                await P.userPopup(filter, data)
            C.closeLoading()
            if (data && data.id) {
                // 判断是否重复
                let key = C.inarray({ userid: data.id }, this.yejilist)
                if (key == -1) {
                    scope.row.userid = data.id
                    scope.row.name = data.name
                    scope.row.bumenid = data.bumenid
                    scope.row.xiaozuid = data.xiaozuid
                    this.nextInput(this.yejiListRef)
                } else if (scope.$index == key) {
                    this.nextInput(this.yejiListRef)
                } else {
                    C.error('选择员工重复！')
                    e.target.select()
                    return false
                }
            }
        },
        async firstPopupType(scope) {
            this.setIndex(scope.$index, 2, this.orderListRef)
            let data = await P.openOrderGoodsPopup({ guestid: this.ginfo.id, keywords: '', rowtype: scope.row.rowtype })
            if (data && data.id) {
                let consumetype = scope.row.rowtype == 1 || scope.row.rowtype == 2 ? 1 : scope.row.rowtype == 3 ? 2 : 3
                let type = scope.row.rowtype == 1 || scope.row.rowtype == 4 ? 1 : 2
                // console.log(data)
                // 不存在插入，存在进行如下判断
                // 有数据同一行跳转，有数据不同行提示不能重复
                // 判断是否重复（如果rowtype=1或=2产品项目，可通过rowtype和typeid判断）
                // 如果rowtype=3 可以通过rowtype和guestcardinfoid判断
                // 如果rowtype=4 可通过rowtype和tempid判断

                let index, rowdata = {
                    type: type,
                    typename: data.name,
                    consumetype: consumetype,
                    price: data.price,
                    brandid: data.brandid,
                    goodsnum: data.nums
                }
                switch (scope.row.rowtype) {
                    case 1:
                    case 2:
                        index = C.inarray({ rowtype: scope.row.rowtype, typeid: data.id }, this.orderlist)
                        rowdata = Object.assign(rowdata, {
                            typeid: data.id,
                            amount: data.price,
                        })
                        break
                    case 3:
                        index = C.inarray({ rowtype: scope.row.rowtype, guestcardinfoid: data.id }, this.orderlist)
                        let amount = data.cardtype == 1 ? data.xhprice : data.disprice.toFixed(2)
                        let discount = data.cardtype == 1 ? (amount / data.price).toFixed(2) : data.discount
                        rowdata = Object.assign(rowdata, {
                            typeid: data.subjectid,
                            amount: amount,
                            nownum: data.cardtype == 1 ? '' : data.nownum,
                            discount: discount,
                            cardtype: data.cardtype,
                            cardname: data.cardname,
                            guestcardid: data.cardid,
                            guestcardinfoid: data.id,
                            usecard: data.cardtype == 1 ? 0 : data.disprice.toFixed(2),
                        })
                        break
                    case 4:
                        index = C.inarray({ rowtype: scope.row.rowtype, tempid: data.id }, this.orderlist)
                        rowdata = Object.assign(rowdata, {
                            typeid: data.goodsid,
                            nownum: data.nownum,
                            discount: 0,
                            amount: 0,
                            brandid: data.brandid,
                            tempid: data.id
                        })
                        break
                }

                if (index == -1) {
                    scope.row = Object.assign(scope.row, rowdata)
                    this.nextInput(this.orderListRef)
                } else if (scope.$index == index) {
                    this.nextInput(this.orderListRef)
                } else {
                    C.error('选择数据重复！')
                    // e.target.select()
                    return false
                }
            }
        },
        deleterow: C.deleterow,
        closewin: function() {
            C.closeBrowserWindow()
        },
        getTotal: function(row) {
            // 检查数量是否超出（什么时候检查：1，卡耗且为次卡，2，暂存判断数量）
            if (row.consumetype == 2 && row.cardtype == 2 || row.consumetype == 3) {
                if (Number(row.num) > Number(row.nownum)) {
                    row.num = row.nownum
                    C.error('数量超出可用数量！')
                }
            }
            if (row.consumetype == 2 && row.cardtype == 2) {
                row.usecard = (row.price * row.discount * row.num).toFixed(2) - row.leftAmount > 0 ? row.leftAmount : (row.price * row.discount * row.num).toFixed(2)
                row.amount = row.usecard
            } else {
                row.amount = (row.price * row.discount * row.num).toFixed(2)
            }
            row.isgift = row.amount == 0 ? 1 : 0
        },
        getdiscount: function(row) {
            row.discount = (row.amount / (row.price * row.num)).toFixed(4)
            row.isgift = row.amount == 0 ? 1 : 0
        },
        changeStatus: function(row) {
            row.discount = row.isgift ? 0 : 1
            this.getTotal(row)
        },
        sumorderlist: function(param) {
            const { columns, data } = param
            const sums = []
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = '合计'
                    return
                }
                if (index == 5 || index == 9 || index == 10 || index == 11 || index == 12 || index == 8) {
                    const values = data.map(item => Number(item[column.property]))
                    if (!values.every(value => isNaN(value))) {
                        sums[index] = values.reduce((prev, curr) => {
                            const value = Number(curr)
                            if (!isNaN(value)) {
                                return prev + curr
                            } else {
                                return prev
                            }
                        }, 0)
                        sums[index] = sums[index].toFixed(2)
                    } else {
                        sums[index] = 'N/A'
                    }
                }
            })
            return sums
        },
        submitorder: async function(g) {
            if (!this.ginfo.id) {
                C.error('请添加客户！')
                return false
            }
            if (this.orderlist.length <= 0) {
                C.error('请添加产品或项目！')
                return false
            } else {
                for (var i = 0; i < this.orderlist.length; i++) {
                    if (this.orderlist[i].goodsnum && this.orderlist[i].num > this.orderlist[i].goodsnum) {
                        C.error('选择的产品数量超出了库存数量！')
                        return false
                    }
                }
            }
            // 进行匹配
            let usebalance = 0,
                usegiftbalance = 0
            for (let i = 0; i < this.orderlist.length; i++) {
                if (this.orderlist[i].num <= 0 || this.orderlist[i].discount < 0) {
                    C.error('第' + (i + 1) + '行数量或者扣填写不正确！')
                    return false
                }
                let uamount = C.accAdd(C.accAdd(this.orderlist[i].usemoney, this.orderlist[i].usebalance), this.orderlist[i].usegiftbalance)
                uamount = C.accAdd(this.orderlist[i].usecard, uamount)
                if (C.accSub(this.orderlist[i].amount, uamount) != 0) {
                    C.error('第' + (i + 1) + '行金额填写不对称！')
                    return false
                }
                // 判断余额或者赠送余额是否足够
                usebalance += Number(this.orderlist[i].usebalance)
                usegiftbalance += Number(this.orderlist[i].usegiftbalance)
            }
            let initConfig = JSON.parse(C.getLocalStorage('initConfig'))
            if (initConfig.isqian) {
                if (usebalance > this.ginfo.balance) {
                    if (!confirm('该客户余额已不足，会产生欠款，确定要继续吗？')) {
                        return false
                    }
                }
            } else {
                if (usebalance > this.ginfo.balance) {
                    C.error('客户账户余额不足以支付当前订单！')
                    return false
                }
            }

            if (usegiftbalance > this.ginfo.giftbalance) {
                C.error('客户账户赠送余额不足以支付当前订单！')
                return false
            }
            this.order.usegiftbalance = this.fenpeijine.usegiftbalance
            this.order.usebalance = this.fenpeijine.usebalance
            this.order.usemoney = this.fenpeijine.usemoney
            this.order.usecard = this.fenpeijine.usecard
            if (this.issanke) {
                this.ginfo = {
                    id: this.ginfoid,
                    name: '散客'
                }
            }
            this.order.crossShop = 0
            let shopid = JSON.parse(C.getLocalStorage('initConfig')).shopid
            if (this.ginfo.departmentid != 0 && shopid != this.ginfo.departmentid) {
                this.order.crossShop = 1
            }
            let data = {
                order: this.order,
                ginfo: this.ginfo,
                orderlist: this.orderlist
            }

            /*console.log(data)
            return false*/

            let res = await C.ajax('/shop/order/newopenorder', { data: JSON.stringify(data) }, 'post')
            if (res) {
                C.success(res.data.info)
                this.order.id = res.data.id
                this.order.status = 0
                this.step(1)
            }
        },
        changesanke: function() {
            this.ginfo = {}
            this.orderlist = []
            if (this.issanke) {
                this.ginfo.id = 1
                this.ginfoid = 1
                this.ginfo.name = '散客'
            }
        },

        step: async function(index) {
            // 第一步，如果有id掉数据，没有添加
            // 
            // 步骤说明：订单的status=0可以在0,1页面，status=1可以在1,2页面，status=3可以在2,3页面

            if (0 == index && (this.order.status && this.order.status != 0)) {
                C.error('请先反结账订单再编辑！')
                return false
            }
            if (1 == index && !this.order.id) {
                C.error('请先保存订单！')
                return false
            }
            if (2 == index) {
                if (!this.order.id || this.order.status == 0) {
                    C.error('请先结账！')
                    return false
                }
            }
            if (1 == index) {
                let filter = { pagesize: 30, currentpage: 1, ismanage: 1 }
                let user = await C.ajax('/shop/popup/getappuser', { filter: JSON.stringify(filter) }, 'post')
                this.userlist = user.list
            }

            if (this.order.id) {
                this.getorderinfo(this.order.id)
            }
            if (2 == index || 3 == index) {
                this.getjisuanticheng(this.order.id)
            }
            this.active = index
        },


        // 结账
        paysubmit: async function() {
            // 判断是否有未分配的业绩和收款金额
            if (this.yingshoujine != 0) {
                C.error('应收现金不正确！')
                return false
            }
            if (this.yingfenyeji.yingfenxianjin != 0 || this.yingfenyeji.yingfenkahao != 0) {
                C.error('分配业绩金额不正确！')
                return false
            }

            let err = false
            let isqian = false
            let initConfig = JSON.parse(C.getLocalStorage('initConfig'))
            this.paylist.forEach((row) => {
                if (!row.accountid || row.accountid <= 0) {
                    C.error('收款账户填写不正确！')
                    err = true
                }
                if (row.paymoney <= 0) {
                    C.error('收款金额填写不正确！')
                    err = true
                }
            })

            if (this.yejilist.length) {
                for (var i = 0, xjlen = this.yejilist.length; i < xjlen; i++) {
                    if (!this.yejilist[i].userid || this.yejilist[i].userid <= 0) {
                        C.error('员工信息填写不正确！')
                        return false
                    }
                    if (this.yejilist[i].xianjinyeji <= 0 && this.yejilist[i].kahaoyeji <= 0 || this.yejilist[i].xianjinyeji < 0 || this.yejilist[i].kahaoyeji < 0) {
                        C.error(this.yejilist[i].name + '[员工]分配业绩不正确！')
                        return false
                    }
                }
            }
            if (this.ginfo.balance - this.fenpeijine.usebalance < 0) isqian = true
            if (this.ginfo.giftbalance - this.fenpeijine.usegiftbalance < 0) {
                C.error('赠送余额不足！')
                return false
            }
            if (err) return false
            if (isqian && !initConfig.isqian) {
                C.error('该客户账户余额不足！')
                return false
            }
            if (isqian && !confirm('该客户余额已不足，会产生欠款，确定要继续吗？')) return false

            // 判断结账时间

            let data = {
                order: this.order,
                paylist: this.paylist,
                yejilist: this.yejilist
            }
            /*console.log(data)
            return false*/
            let res = await C.ajax('/shop/order/jiezhang', { data: JSON.stringify(data) }, 'post')
            if (res) {
                C.success(res.data.info)
                this.order.status = 1
                this.step(2)
            }
        },
        chongxinfenpei: async function() {
            if (this.yingfenyeji.yingfenxianjin != 0 || this.yingfenyeji.yingfenkahao != 0) {
                C.error('分配业绩金额不正确！')
                return false
            }
            if (this.yejilist.length) {
                for (var i = 0, xjlen = this.yejilist.length; i < xjlen; i++) {
                    if (this.yejilist[i].xianjinyeji <= 0 && this.yejilist[i].kahaoyeji <= 0 || this.yejilist[i].xianjinyeji < 0 || this.yejilist[i].kahaoyeji < 0) {
                        C.error(this.yejilist[i].name + '[员工]分配业绩不正确！')
                        return false
                    }
                }
            }
            let data = {
                order: this.order, // 订单ID                                          
                yejilist: this.yejilist
            }
            // return false
            let res = await C.ajax('/shop/order/edityejifenpei', { data: JSON.stringify(data) }, 'post')
            if (res) {
                C.success(res.data.info)
            }
        },
        fanjiezhang: async function() {
            await C.confirm('此操作将清除已结账的信息, 是否继续?', async() => {
                let res = await C.ajax('/shop/order/fanjiezhang', { id: this.order.id }, 'post')
                if (res) {
                    C.success(res.data.info)
                    // 反结账之后要操作的内容
                    this.order.status = 0
                    this.step(1)
                }
            })
        },
        getjisuanticheng: async function(id) {
            let data = await C.ajax('/shop/order/getjisuanticheng', { id: id }, 'post')
            if (data) {
                this.tichenglist = data.orderlist
                this.fenpeilist = data.fenpeilist
            }
        },
        adduser: async function() {
            let data = await C.openBrowserWindow('/selectAppUser', {}, {
                width: 1200,
                height: 860,
                transparent: true,
                frame: false,
                // openDevTools: true,
                useSpa: true,
                spaModel: 'shop'
            })
            if (data) {
                let ot = this.order.ordertype == 1 ? 'KKD' : this.order.ordertype == 2 ? 'LSD' : 'CZD'
                data.forEach((row) => {
                    // 判断是否重复
                    if (C.inarray({ userid: row.id }, this.fenpeilist) === -1) {
                        this.fenpeilist.push({
                            id: '',
                            xianjintichengbi: 0,
                            kahaotichengbi: 0,
                            xianjinticheng: 0,
                            kahaoticheng: 0,
                            xianjinyeji: 0,
                            kahaoyeji: 0,
                            name: row.name,
                            addtype: 1,
                            orderid: this.order.id,
                            userid: row.id,
                            xiaozuid: row.xiaozuid,
                            bumenid: row.bumenid,
                            qitaticheng: 0,
                            ordertype: ot,
                            guestid: this.order.guestid,
                            addtime: this.order.addtime,
                            shopid: this.order.departmentid,
                            fuwutype: 0,
                            shougongticheng: 0
                        })
                    }
                })
            }
        },
        gettichengsum: function() {
            return ['合计', '', '', '', '', '', '', this.sumticheng.xianjinticheng, this.sumticheng.kahaoticheng, this.sumticheng.shougongticheng]
        },
        getSummaries: function(param) {
            const { columns, data } = param
            const sums = []
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = '合计'
                    return
                }

                const values = data.map(item => Number(item[column.property]))
                if (!values.every(value => isNaN(value))) {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr)
                        if (!isNaN(value)) {
                            return prev + curr
                        } else {
                            return prev
                        }
                    }, 0)
                    sums[index] = sums[index].toFixed(2)
                    sums[index] += ' 元'
                } else {
                    sums[index] = 'N/A'
                }
            })
            return sums
        },
        fenpeiticheng: async function(r) {
            // 进行判断
            // return false
            let url = r ? '/shop/kaidancheck/chongxinfenpei' : '/shop/kaidancheck/fenpeiticheng'
            let data = { userinfo: JSON.stringify(this.fenpeilist), orderid: this.order.id, ordertype: this.order.ordertype }

            let e = false
            let that = this
            if (this.fenpeilist.length <= 0) {
                C.confirm('该单据将不产生任何提成，确定继续吗？', async() => {
                    let res = await C.ajax(url, data, 'post')
                    if (res) {
                        C.success(res.data.info)
                        that.step(3)
                    }
                })
            } else {
                this.fenpeilist.forEach((row) => {
                    if (row.xianjinticheng < 0 || row.kahaoticheng < 0 || row.shougongticheng < 0 || row.qitaticheng < 0) e = true
                })
                if (e) {
                    C.error('数据格式填写不正确')
                    return false
                }
                let res = await C.ajax(url, data, 'post')
                if (res) {
                    C.success(res.data.info)
                    that.step(3)
                }
            }
        },
        getorderinfo: async function(id) {
            let data = await C.ajax('/shop/order/getorderinfo', { orderid: id }, 'post')
            if (data) {
                // 赋值用户信息
                data.ginfo.headurl = data.ginfo.headurl != 0 ? data.ginfo.headurl : headImg
                this.ginfo = data.ginfo
                this.issanke = this.ginfo.id == 1 || this.ginfo.id == 2 ? true : false
                if (this.issanke) this.ginfoid = this.ginfo.id
                // 整合订单列表信息
                if (this.order.status === '') {
                    this.active = Number(data.orderinfo.status) + 1
                    if (this.active == 2 || this.active == 3) {
                        this.getjisuanticheng(this.order.id)
                    }
                }
                data.orderlist.forEach((row) => {
                    if (row.consumetype == 1 && row.type == 1) {
                        row.rowtype = 1
                    } else if (row.consumetype == 1 && row.type == 2) {
                        row.rowtype = 2
                    } else if (row.consumetype == 2) {
                        row.rowtype = 3
                    } else {
                        row.rowtype = 4
                    }
                })
                if (this.orderlist.length <= 0) this.orderlist = data.orderlist
                // 赋值订单信息
                this.order = data.orderinfo
                this.paylist = data.alist
                this.yejilist = data.yejilist
            }
        },
        dayin: function() {
            C.openBrowserWindow('/printOpenOrder', { id: this.order.id }, { width: 245, height: 900, useSpa: true, spaModel: 'print' })
        },
        quxiaofenpei: function() {
            C.confirm('确定要撤销吗？', async() => {
                let data = await C.ajax('/shop/kaidancheck/fanfenpeiticheng', { id: this.order.id }, 'post')
                if (data) {
                    C.success(data.data.info)
                    this.order.status = 1
                }
            })
        },
        openGuestPage(id) {
            Guest.openGuestPage(id)
        }
    }),
    computed: {
        shishouxianjin: function() {
            let m = 0
            this.paylist.forEach((row) => {
                m += Number(row.paymoney)
            })
            return m.toFixed(2)
        },
        yingshoujine: function() {
            return Number(this.fenpeijine.usemoney - this.shishouxianjin).toFixed(2)
        },
        yingfenyeji: function() {
            let o = {}
            o.yingfenxianjin = (this.fenpeijine.usemoney - this.shifenyeji.shifenxianjin).toFixed(2)
            o.yingfenkahao = (this.fenpeijine.usecard + this.fenpeijine.usebalance + this.fenpeijine.usegiftbalance - this.shifenyeji.shifenkahao).toFixed(2)
            return o
        },
        shifenyeji: function() {
            let o = { shifenxianjin: 0, shifenkahao: 0 }
            this.yejilist.forEach((row) => {
                o.shifenxianjin += Number(row.xianjinyeji)
                o.shifenkahao += Number(row.kahaoyeji)
            })
            return o
        },
        fenpeijine: function() {
            let o = { putong: 0, kahao: 0, zancun: 0, zongji: 0, usemoney: 0, usebalance: 0, usegiftbalance: 0, usecard: 0 }
            this.orderlist.forEach((row) => {
                if (row.consumetype == 1) {
                    o.putong += Number(row.amount)
                } else if (row.consumetype == 2) {
                    o.kahao += Number(row.amount)
                } else {
                    o.zancun += Number(row.amount)
                }
                o.zongji += Number(row.amount)

                o.usemoney += Number(row.usemoney)
                o.usebalance += Number(row.usebalance)
                o.usegiftbalance += Number(row.usegiftbalance)
                o.usecard += Number(row.usecard)
            })
            return o
        },
        sumticheng: function() {
            let o = { xianjinticheng: 0, kahaoticheng: 0, shougongticheng: 0 }
            this.tichenglist.forEach((row) => {
                o.xianjinticheng += Number(row.xianjinticheng)
                o.kahaoticheng += Number(row.kahaoticheng)
                o.shougongticheng += Number(row.shougongticheng)
            })
            return o
        }
    },
    mounted: async function() {
        let gid = C.getDatas().gid
        this.order.id = C.getDatas().id ? Number(C.getDatas().id) : ''
        this.order.status = C.getDatas().status ? Number(C.getDatas().status) : ''
        if (gid) {
            let data = await C.ajax('/shop/guest/guest', { gid: gid })
            if (data) {
                data.headurl = data.headurl != 0 ? data.headurl : headImg
                this.ginfo = data
            }
        }
        if (!this.order.status && !this.order.id) {
            this.step(0)
        } else {
            this.step(Number(this.order.status) + 1)
        }
    }
}
</script>
<style>
.el-input.is-disabled .el-input__inner {
    color: #324057;
}

.el-textarea__inner {
    resize: none;
}

#discount {
    width: 100px;
}

#discount i {
    display: none;
}

.el-switch.is-checked .el-switch__core {
    border-color: #20a0ff !important;
    background-color: #20a0ff !important;
}

.money input {
    background: #defff5;
}

.el-table__row .cell {
    padding: 0px;
    text-align: center;
}

#opencard {
    color: #000;
    height: 100%;
}

.itemClass .el-form-item__content {
    height: 100%;
    position: absolute;
    display: flex;
    flex-direction: column;
    margin: 0px !important;
    width: 100%;
    padding-left: 80px;
    box-sizing: border-box;
}

.itemClass {
    height: 100%;
    position: relative;
}
</style>